#include "game.h"

sObj*menu_start;
sObj*menu_load;//显示进度
sObj*menu_seek;
//绘制按钮
void drawTextBtn(void*ob)
{
 sObj*obj = ob;
 sCam*cam = &(_room->cam);
 //更新精灵
 obj->act = obj->data[0];
 //按照.9图绘制
 sGuiDrawBtnV9(obj,obj->x-cam->x,
  obj->y-cam->y,32,32,6,6);
 //绘制文字
 sGuiDrawText(obj);
}

//监听按钮
void btnClick(sObj*obj,int act)
{
 int num;
 sObj*temp;
 char data[100];
 if(act==MS_UP)
 {
  switch(obj->id)
  {
   case 1:
   toast("up",0);
   break;
   
   case 3:
   obj->act = !obj->act;
   if(obj->act)
   	toast("true",0);
   else
   	toast("false",0);
   break;
   
   case 10:
    num = 
    sGuiGetSeekBar(menu_seek);
    sGuiSetSeekBar(menu_seek,
    num-5);
   break;
    
   case 11:
    num = 
    sGuiGetSeekBar(menu_seek);
    sGuiSetSeekBar(menu_seek,
    num+5);
   break;
  }
 }
 else if(act==MS_DOWN)
 {
  switch(obj->id)
  {
   case 1:
   toast("down",0);
   break;
  }
 }
 else
 {
  switch(obj->id)
  {
   case 1:
   toast("long",0);
   break;
   
   case 2:
    temp = (sObj*)obj->data[5];
    num = sGuiGetSeekBar(temp);
    sprintf(data,"bar1:%d",num);
    sGuiSetText(menu_load,data);
   break;
   
   case 4:
    temp = (sObj*)obj->data[5];
    num = sGuiGetSeekBar(temp);
    sprintf(data,"bar2:%d",num);
    sGuiSetText(menu_load,data);
   break;
  }
 }
}

//房间创建
void menuCreate(void*rm)
{
 sSpr*spr;
 sObj*obj,*obj2;
 sRoom*room = rm;
 //提示文字
 GM.fnt_20_cn = (_FNT*)
 getRes("fnt/font_20_cn.fnt",
  tFnt)->id;
 //菜单文字
 GM.fnt_24_cn = (_FNT*)
 getRes("fnt/font_24_cn.fnt",
  tFnt)->id;
 //logo文字
 GM.fnt_64 = (_FNT*)
 getRes("fnt/font_64.fnt",tFnt)->id;
 
 //载入精灵
 spr = (sSpr*)
 getRes("spr/btn.spr",tSpr)->id;
 //创建按钮
 obj = sGuiNewBtn(SW/2-48,SH-100,
  spr,btnClick);
 sGuiBtnLong(obj,btnClick,300);
 obj->id = 1;
 obj->sprw = 96;
 obj->sprh = 48;
 obj->draw = drawTextBtn;
 obj->data[8] = (int)GM.fnt_24_cn;
 obj->data[9] = (int)"闯关";
 sRoomAddObj(room,obj);
 
 //创建按钮
 obj = sGuiNewBtn(100,320,
  spr,btnClick);
 obj->id = 10;
 obj->sprw = 40;
 obj->sprh = 40;
 obj->draw = drawTextBtn;
 obj->data[8] = (int)GM.fnt_24_cn;
 obj->data[9] = (int)"-";
 sRoomAddObj(room,obj);
 
 obj = sGuiNewBtn(SW-140,320,
  spr,btnClick);
 obj->id = 11;
 obj->sprw = 40;
 obj->sprh = 40;
 obj->draw = drawTextBtn;
 obj->data[8] = (int)GM.fnt_24_cn;
 obj->data[9] = (int)"+";
 sRoomAddObj(room,obj);
 
 //创建文本
 obj = 
 sGuiNewText(SW/2-50,605,"开关示例",GM.fnt_24_cn);
 sRoomAddObj(room,obj);
 spr = (sSpr*)
 getRes("spr/box.spr",tSpr)->id;
 //创建选择按钮
 obj = 
 sGuiNewBtn(SW/2+50,
  600,spr,btnClick);
 obj->id = 3;
 obj->sprw = 32;
 obj->sprh = 32;
 sRoomAddObj(room,obj);
 
 //创建文本
 obj = 
 sGuiNewText(0,30,"MINE",GM.fnt_64);
 obj->sprw = SW;
 obj->sprh = 48;
 sRoomAddObj(room,obj);
 
 //创建文本
 obj = sGuiNewText(0,120,
  "SWEEPER",GM.fnt_64);
 obj->sprw = SW;
 obj->sprh = 48;
 sRoomAddObj(room,obj);
 
 //创建进度条
 obj = 
 sGuiNewText(0,270,"进度条",GM.fnt_24_cn);
 sRoomAddObj(room,obj);
 obj = sGuiNewSeekView(0,300,
  SW,10,100);
 sGuiSetSeekBar(obj,50);
 sRoomAddObj(room,obj);
 menu_seek = obj;
 
 //创建拖动
 obj = 
 sGuiNewText(100,420,"可拖动进度条1",GM.fnt_24_cn);
 sRoomAddObj(room,obj);
 obj = sGuiNewSeekBar(100,450,
  SW-200,10,200,15,btnClick);
 sGuiSetSeekBar(obj,0);
 sRoomAddObj(room,obj);
 obj2 = sGuiGetSeekDrag(obj);
 sRoomAddObj(room,obj2);
 //创建一个进度显示
 obj = 
 sGuiNewText(100,490,
 "0",GM.fnt_24_cn);
 sRoomAddObj(room,obj);
 menu_load = obj;
 
  //创建拖动
 obj = 
 sGuiNewText(100,520,"可拖动进度条2",GM.fnt_24_cn);
 sRoomAddObj(room,obj);
 obj = sGuiNewSeekBar(100,550,
  SW-300,10,100,15,btnClick);
 sGuiSetSeekBar(obj,0);
 sRoomAddObj(room,obj);
 obj2 = sGuiGetSeekDrag(obj);
 obj2->id = 4;
 sRoomAddObj(room,obj2);
}

//绘制房间
void menuDraw(void*rm)
{
 sRoom*room = rm;
 sCam*cam = &(room->cam);
 sDrawSenObjCam(room->sen,cam);
}

//房间事件
void menuEvent(int type,int p1,int p2)
{
 //退出页面
 if(KY_UP==type)
 {
  switch(p1)
  {
   case _BACK:
   sExitRoom(_room);
   exit();
   break;
  }
 }
}

//创建房间
int createMenu()
{
 if(GM.rmMenu==NULL)
 {
  GM.rmMenu = 
  sNewRoom(SW,SH,100);
 }
 GM.rmMenu->create = menuCreate;
 GM.rmMenu->draw = menuDraw;
 GM.rmMenu->event = menuEvent;
 return 0;
}
